package com.sky.mapper.User;

import com.sky.annotation.AutoFill;
import com.sky.entity.ShoppingCart;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 条件查询
     *
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 更新商品数量
     *
     * @param shoppingCart
     */
   // @AutoFill(OperationType.UPDATE)
    void updateById(ShoppingCart shoppingCart);

    /**
     * 插入购物车数据
     *
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
   // @AutoFill(OperationType.INSERT)
    void insert(ShoppingCart shoppingCart);


    /**
     * 根据菜品id查询
     * @param shoppingCart
     * @return
     */
    @Select("select * from shopping_cart where dish_id = #{dishId} or setmeal_id = #{setmealId}")
    ShoppingCart selectByCart(ShoppingCart shoppingCart);

    /**
     * 删除菜品
     * @param id
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteCart(Long id);

    /**
     * 查询全部
     * @return
     */
    @Select("select * from shopping_cart")
    List<ShoppingCart> getAll();

    /**
     * 批量插入购物车数据
     *
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
